﻿// -------------------------------------------------------------------------
//    @FileName         :    NFTransAccCreateRole.h
//    @Author           :    gaoyi
//    @Date             :    24-8-21
//    @Email            :    445267987@qq.com
//    @Module           :    NFTransAccCreateRole
//
// -------------------------------------------------------------------------

#pragma once

#include "proto_cs.nanopb.h"
#include "proto_cs.pb.h"
#include "NFLogicCommon/NFBaseDefine.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"
#include "NFServerComm/NFServerCommon/NFCacheDataGetTrans.h"

namespace proto_ff
{
    class tbRoleList;
    class Proto_Zone2OnLineCreateRoleReq;
}

class NFOnlineAcc;

typedef enum enTransCreateRoleState
{
    EN_TCRS_INIT = 0,
    EN_TCRS_INSERT_NAME = 1,
    EN_TCRS_GET_ROLE_LIST = 2,
    EN_TCRS_INSERT_ROLE_LIST = 3,
    EN_TCRS_UPDATE_ROLE_LIST = 4,
} ETransCreateRoleState;

const int MAX_FRIENDS_UIN_NUM = 50;

struct TCreateRoleReq
{
    TCreateRoleReq()
    {
        if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
        {
            CreateInit();
        }
        else
        {
            ResumeInit();
        }
    }

    int CreateInit()
    {
        m_iActorID = 0;
        m_iExTransferID = 0;
        m_cSecReportStr = 0;
        return 0;
    }

    int ResumeInit()
    {
        return 0;
    }

    int32_t m_iActorID;
    NFShmString<MAX_NAME_LEN> m_szName;
    int32_t m_iExTransferID;
    char m_cSecReportStr;

    NFShmVector<uint64_t, MAX_FRIENDS_UIN_NUM> m_aullFriendUin;
};

class NFTransAccCreateRole : public NF_OBJECT_TEMPLATE_MACRO(NFTransAccCreateRole, EOT_ONLINE_TRANS_ACC_CREATE_ROLE, NFCacheDataGetTrans)
public:
    NFTransAccCreateRole();

    ~NFTransAccCreateRole() override;

    int CreateInit();

    int ResumeInit();
public:
    int Init(int zoneId, uint64_t playerUin, int platformType, int fromBusId, int transId, const proto_ff::Proto_Zone2OnLineCreateRoleReq &oCreateRoleReq);
    int StartInsertName();
public:
    int OnTransFinished(int iRunLogicRetCode) override;
    int InsertCacheDataRes(int ullId, int iTableId, int iReason, int32_t errCode, google::protobuf::Message* pMessage) override;
    int GetCacheDataRes(int ullId, int iTableId, int iReason, int32_t errCode, google::protobuf::Message* pMessage) override;
    int SaveCacheDataRes(int ullId, int iTableId, int iReason, int32_t errCode) override;
private:
    int StartGetRoleList();
    int StartInsertRoleList();
    int StartUpdateRoleList();

    int MakeNewRoleList(int iWorldType, uint64_t ullUin, const std::string &source_id, const std::string &login_source, proto_ff::tbRoleList &tbRoleList);

    int InitData(const proto_ff::Proto_Zone2OnLineCreateRoleReq &oCreateRoleReq);

private:
    int ProInsertNameRes(int err_code);

    int ProInsertRoleListRes(int err_code, google::protobuf::Message* pMessage);

    int ProGetRoleListRes(int err_code, google::protobuf::Message* pMessage);

    int ProUpdateRoleListRes(int err_code);

private:
    int NotifyCreateRoleRsp(NFOnlineAcc *pAcc, int iResult);
    std::string GetDebugInfo() const;
private:
    TCreateRoleReq m_stCreateRoleReq;
    uint64_t m_ullRoleID;
    int m_fromBusId;
    int m_transId;
    int m_zoneId;
    int m_platformType;
    uint64_t m_playerUin;
    NFShmString<64> reg_channel_str;
    NFShmString<64> login_channel_str;
    NFShmString<64> m_accountId;
};
